<?
/**
 * Database object to list events with proper joins
 */
(basename($_SERVER['PHP_SELF']) == basename(__FILE__)) && die('Access Denied');

class EventList extends HistoryTimelineDbo {

/**
 * Constructor
 */
public function __construct() {
	parent::__construct();

	// child instances
	$C = $this->getDbo('CategoryDbo');
	$E = $this->getDbo('EventDbo');
	$S = $this->getDbo('SourceDbo');

	// properties (Event)
	$this->propertyAdd('EventDate',    'e.' . $E->getPropertyField('EventDate'));
	$this->propertyAdd('EventEnabled', 'e.' . $E->getPropertyField('Enabled'));
	$this->propertyAdd('EventText',    'e.' . $E->getPropertyField('EventText'));
	$this->propertyAdd('EventId',      'e.' . $E->getPropertyField('Id'));
	// properties (Category)
	$this->propertyAdd('CategoryColor', 'c.' . $C->getPropertyField('Color'));
	$this->propertyAdd('CategoryDesc',  'c.' . $C->getPropertyField('Desc'));
	$this->propertyAdd('CategoryId',    'c.' . $C->getPropertyField('Id'));
	$this->propertyAdd('CategoryTag',   'c.' . $C->getPropertyField('Tag'));
	// properties (Source)
	$this->propertyAdd('SourceId',   's.' . $S->getPropertyField('Id'));
	$this->propertyAdd('SourceText', 's.' . $S->getPropertyField('Source'));

	// id property
	$this->setIdProperty('EventId');

	// Set numeric properties
	$this->setPropertyIsNumeric('CategoryId');
	$this->setPropertyIsNumeric('EventEnabled');
	$this->setPropertyIsNumeric('EventId');
	$this->setPropertyIsNumeric('SourceId');

	// Set date properties
	$this->setPropertyIsDate('EventDate');

	// Descriptions (Event)
	$this->setPropertyDescription('EventDate', 'Event Date');
	$this->setPropertyDescription('EventEnabled', 'Event Enabled');
	$this->setPropertyDescription('EventText', 'Event');
	$this->setPropertyDescription('EventId', 'Event ID');
	// Descriptions (Category)
	$this->setPropertyDescription('CategoryColor', 'Category Color');
	$this->setPropertyDescription('CategoryDesc', 'Category Description');
	$this->setPropertyDescription('CategoryId', 'Category ID');
	$this->setPropertyDescription('CategoryTag', 'Category');
	// Descriptions (Source)
	$this->setPropertyDescription('SourceId', 'Source ID');
	$this->setPropertyDescription('SourceText', 'Source');

	// initialize new search
	$this->searchReset();
	}

/**
 * Override the parent...
 */
public function searchReset() {
	parent::searchReset();

	// child instances
	$C = $this->getDbo('CategoryDbo');
	$E = $this->getDbo('EventDbo');
	$S = $this->getDbo('SourceDbo');

	// master table
	$this->setSearchFromClause($E->getDatabaseTable() . ' AS e');

	// add in joins
	$this->setSearchJoin('LEFT JOIN ' . $C->getDatabaseTable() . ' c on e.'
	               . $E->getPropertyField('CategoryId') . ' = c.'
	               . $C->getPropertyField('Id'));
	$this->setSearchJoin('LEFT JOIN ' . $S->getDatabaseTable() . ' s on e.'
	               . $E->getPropertyField('SourceId') . ' = s.'
	               . $S->getPropertyField('Id'));
	return true;
	}
}
?>
